local hanqi = fk.CreateSkill {
  name = "th_hanqi",
  tags = {  },
}

local spec = { ---@type TrigSkelSpec<fun(self: TriggerSkill, event: AimEvent, target: ServerPlayer, player: ServerPlayer, data: AimData):any>
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(hanqi.name) and data.firstTarget and data.card and
    (event == fk.TargetSpecifying or data.from ~= player) then
      return #data:getExtraTargets({ bypass_times = true, bypass_distances = false }) ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = {}
    for _, to in ipairs(data:getExtraTargets({ bypass_times = true, bypass_distances = false })) do
      if to:distanceTo(player) == 1 then
        table.insert(tos, to)
      end
    end
    local selected = room:askToChoosePlayers(player, {
      targets = tos,
      min_num = 1,
      max_num = #tos,
      prompt = "#th_hanqi-invoke:::".. data.card:toLogString(),
      skill_name = hanqi.name
    })
    if #selected ~= 0 then
      event:setCostData(self, { tos = selected })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local tos = {}
    for _, to in ipairs(dat.tos) do
      local cards = room:askToDiscard(to, {
        min_num = 2,
        max_num = 2,
        include_equip = true, 
        skill_name = hanqi.name, 
        prompt = "#th_hanqi_discard-ask:::" .. data.card:toLogString()
      })
      if #cards < 2 then
        table.insert(tos, to)
      end
    end
    data:addTarget(tos)
  end,
}

hanqi:addEffect(fk.TargetSpecifying, spec)
hanqi:addEffect(fk.TargetConfirming, spec)

Fk:loadTranslationTable{
  ["th_hanqi"] = "寒气",
  [":th_hanqi"] = "当你使用牌指定目标或成为其他角色使用牌的目标时，你可以令任意名与你距离为1且能成为此牌额外目标的角色选择一项：1.弃置两张牌；2.成为此牌的额外目标。",

  ["#th_hanqi-invoke"] = "寒气：你可以令任意名与你距离为1且能成为此牌额外目标的角色选择弃牌或成为 %arg 的额外目标",
  ["#th_hanqi_discard-ask"] = "寒气：你须弃置两张牌，否则将成为 %arg 的额外目标",
}

return hanqi